<?php
if (!defined('IN_IA')) {
	die('Access Denied');
}
//获取全局GET，POST
global $_W, $_GPC;
//初始化模块
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
//获取openid
$openid = m('user')->getOpenid();
if($operation == 'display'){
	$info = pdo_fetch('select * from '.tablename('zige').' where openid=:openid order by id desc',array(":openid"=>$openid));
        //判断是否审核通过
        if($info['status']==1){
           header("location: http://wx.lanxuevip.com/app/index.php?i=5&c=entry&id={$info['goodsid']}&do=goodsdetails&m=feng_fightgroups&opid=".$openid); 
           exit; 
        }
	//日期转换
	if($info['time_begin'] != ''){
		$info['time_begin']=date('Y-m-d H:i:s',$info['time_begin']);
	}
	if($info['time_end'] != 0){
		$info['time_end']=date('Y-m-d H:i:s',$info['time_end']);
	}
}elseif($_W['isajax']){
	if($operation == 'infoadd'){
		//手机账号验证
                //查询是否插入过
                $goodsinfo=pdo_fetch('select * from '.tablename("tg_goods")." where uniacid=:uniacid and openid=:openid order by id desc",array(':uniacid'=>$_W['uniacid'],':openid'=>$openid));
                if(empty($goodsinfo)){
                    $insert=array(
                     'uniacid'=>$_W['uniacid'],
                     'openid'=>$openid,
                     'gname'=>"蓝血贵族VIP金卡套餐",
                     'gname_two'=>"蓝血贵族VIP银卡套餐",
                     'fk_typeid'=>5,
                     'gnum'=>2515,
                     'groupnum'=>7,
                     'mprice'=>20464,
                     'mprice_two'=>3572,
                     'gprice'=>0.01,//2480
                     'gprice_two'=>0.02,//198
                     'oprice'=>0.02,
                     'gdesc'=>"测试",
                     'gimg'=>"images/5/2017/03/YboonyMhv8bmbMmYMm4nM4nYB470MM.jpg",
                     'gimg_two'=>"images/5/2017/03/fXB0xyqHMJZ96TQR3p8BxhW6R9mwL3.jpg",
                     'isshow'=>1,
                     'salenum'=>795,
                     'createtime'=>time(),
                     'endtime'=>720,
                      'yunfei_id'=>4,
                     'is_discount'=>1,
                      'gdetaile'=>'<p><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/Ms82csRuUp9z38F43f9p939u9O3luG.png" width="100%" alt="images/5/2017/03/Ms82csRuUp9z38F43f9p939u9O3luG.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/Kmn63Hj6Tr16NhTHQt3hyRVrHtwGhR.jpg" width="100%" alt="images/5/2017/03/Kmn63Hj6Tr16NhTHQt3hyRVrHtwGhR.jpg"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/pjc7HhuVZc8urihj8v8t1vvUravRHi.png" width="100%" alt="images/5/2017/03/pjc7HhuVZc8urihj8v8t1vvUravRHi.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/AeCEV2IXF2iYe94m4Z2mGc21ZeZc24.png" width="100%" alt="images/5/2017/03/AeCEV2IXF2iYe94m4Z2mGc21ZeZc24.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/At1i404e7A1QAiIW0Dfi4dpdGi2eDp.png" width="100%" alt="images/5/2017/03/At1i404e7A1QAiIW0Dfi4dpdGi2eDp.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/Mb1Gd0y0gA0b3Dv0Y31W501AuVrGUG.png" width="100%" alt="images/5/2017/03/Mb1Gd0y0gA0b3Dv0Y31W501AuVrGUG.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/MrN5nbL866nhOhnblnso7bU7DNBhHH.png" width="100%" alt="images/5/2017/03/MrN5nbL866nhOhnblnso7bU7DNBhHH.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/QLRA8ZMIx0H10a448210lxzd11X061.png" width="100%" alt="images/5/2017/03/QLRA8ZMIx0H10a448210lxzd11X061.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/FZ58BBbcCcf4B8HUuCzxHMbFMX7CmX.png" width="100%" alt="images/5/2017/03/FZ58BBbcCcf4B8HUuCzxHMbFMX7CmX.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/I2Rke28kD8voDR8ollK2ZnVUREgvLL.png" width="100%" alt="images/5/2017/03/I2Rke28kD8voDR8ollK2ZnVUREgvLL.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/beaaan12ll8qewT8wylazQaAe2a2qs.png" width="100%" alt="images/5/2017/03/beaaan12ll8qewT8wylazQaAe2a2qs.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/LBHtYYvcMZrOMwMm70hBRH0R0T3R7e.png" width="100%" alt="images/5/2017/03/LBHtYYvcMZrOMwMm70hBRH0R0T3R7e.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/Hu0YC3sc6564OLc0Ho60H5f56Y4S44.png" width="100%" alt="images/5/2017/03/Hu0YC3sc6564OLc0Ho60H5f56Y4S44.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/BE24G7b5j5k7U22111k2Zs2N2NKEg2.png" width="100%" alt="images/5/2017/03/BE24G7b5j5k7U22111k2Zs2N2NKEg2.png"/></p>',
                      'gdetaile2'=>'<p><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/MBZqPJm52h455GNBQDxgQ4g3WGNb3w.png" width="100%" alt="images/5/2017/03/MBZqPJm52h455GNBQDxgQ4g3WGNb3w.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/Rvvo6ooOOOD93nn4v6d4684o4432pO.jpg" width="100%" alt="images/5/2017/03/Rvvo6ooOOOD93nn4v6d4684o4432pO.jpg"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/RDkppBakDMpM438spSTAMBTGT4tyAM.png" width="100%" alt="images/5/2017/03/RDkppBakDMpM438spSTAMBTGT4tyAM.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/hnznmOZ1YMnyynro11HPXR1yXOFGoN.png" width="100%" alt="images/5/2017/03/hnznmOZ1YMnyynro11HPXR1yXOFGoN.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/eKlkR9dk66M6rl4PR16km3K44cc6EV.png" width="100%" alt="images/5/2017/03/eKlkR9dk66M6rl4PR16km3K44cc6EV.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/HV51VbvXxcHCPpdvrhQd6bC4Hr6gBP.png" width="100%" alt="images/5/2017/03/HV51VbvXxcHCPpdvrhQd6bC4Hr6gBP.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/SqsAQqwqJQQ1wWGMwCjakmcJGtjwQA.png" width="100%" alt="images/5/2017/03/SqsAQqwqJQQ1wWGMwCjakmcJGtjwQA.png"/><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/images/5/2017/03/kPWvpzkZVKB5gcpYtncfwQsVc2ns8B.png" width="100%" alt="images/5/2017/03/kPWvpzkZVKB5gcpYtncfwQsVc2ns8B.png"/></p>',
                      'starttime'=>strtotime("2017-03-01 18:00"),
                      'overtime'=>strtotime("2017-06-01 18:00")
                    );
                    $info=pdo_insert('tg_goods',$insert);
                    if($info){
                        $goodsinfo['id']=pdo_insertid();
                        pdo_insert('tg_goods_atlas',array('thumb'=>"images/5/2017/03/gDE49n9ml09lgqdL95m53v93Q93iVu.jpg",'g_id'=>$goodsinfo['id']));
                    }else{
                      result_info($info,'申请失败');  
                    }
                }
                //获取数据
		$data=array(
			'openid'=>$openid,
			'name'=>$_GPC['name'],
			'time_begin'=>time(),
			'time_end'=>0,
			'explain'=>$_GPC['applyinfo'],
			'status'=>1,
			'replay'=>0,
			'shopname'=>$_GPC['shopname'],
			'address'=>$_GPC['address'],
                        'goodsid'=>$goodsinfo['id']
		);
                $data['mobile']=$_GPC['mobile'];
                $zige=pdo_fetch("select * from ".tablename("zige")." where openid=:openid and status=1 order by id desc",array(":openid"=>$openid));
		//得到返回值
                if(empty($zige)){
		$result=pdo_insert('zige', $data);
                }else{
                $result=$zige;    
                }
		///返回函数
		result_info($result,'申请失败');
	}elseif($operation == 'update'){
		//获取id
		$id=$_GPC['id'];
		//得到返回值
		$result=pdo_update('zige', array('replay' => 1), array('id' => $id));
		///返回函数
		result_info($result,'重新申请失败');
	}
}
/*
	@函数作用 返回值返回参数
	@param bool $result
	$param string $msg
	@return null
*/
function result_info($result,$msg){
	if($result){
		show_json(1);
	}else{
		show_json(0,$msg);		
	}	
}	
//插入小店资格模板
include $this->template('member/seniority');